package com.example.login.biz.impl;

import com.example.login.biz.YongHuBiz;
import com.example.login.mapper.YongHuMapper;
import org.example.bean.QuanxianInfo;
import org.example.bean.YongHuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class YongHuBizImpl implements YongHuBiz {
    @Autowired
    private YongHuMapper yhm;
    @Override
    public YongHuInfo findYongHuByMima(String youxiang, String mima) {
        return yhm.findYongHuByMima(youxiang,mima);
    }

    @Override
    public void saveYongHu(YongHuInfo yhi) {
        yhm.saveYongHu(yhi);
    }

    @Override
    public Map<String,Object> findAllYongHu(int page,int size) {
        Map<String,Object> map = new HashMap<>();
        List<YongHuInfo> list = yhm.findAllYongHu((page-1)*size,size);
        for (YongHuInfo s:list){
            s.setDengji(yhm.findYongHuQuanXianById(s.getQuanXianId()).getDengji());
        }
        int all = yhm.findAllCount();
        map.put("allPage",all%size==0?(all/size):(all/size+1));
        map.put("rows",list);
        return map;
    }

    @Override
    public void UpdateYongHU(YongHuInfo yhi) {
        yhm.UpdateYongHU(yhi);
    }

    @Override
    public void deleteYongHU(int yongHuId) {
        yhm.deleteYongHU(yongHuId);
    }

    @Override
    public List<QuanxianInfo> findAllQuanXian() {
        return yhm.findAllQuanXian();
    }
}

